﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Story>" %>
<%@ Import Namespace="YoProgramo.Domain.Core.Entities"%>
<%@ Import Namespace="YoProgramo.Domain.BusinessLogic.Service"%>
<%@ Import Namespace="YoProgramo.Domain.Core.Interfaces"%>
<%@ Import Namespace="YoProgramo.BusinessLogic.Service"%>
<%@ Import Namespace="Microsoft.Practices.ServiceLocation"%>


<%  
ICategoryService categoryService =
    ServiceLocator.Current.GetInstance<ICategoryService>();  
IUserRepository userRepository =
    ServiceLocator.Current.GetInstance<IUserRepository>();

IList<ICategory> AllCategories = categoryService.GetAll();
   %>

<%if (Model == null){ %>

    <h2>Enviar Pregunta</h2>

    <%= Html.ValidationSummary("Un error ha ocurrido y no fue posible agregar la pregunta. Chequea los campos.")%>

    <% using (Html.BeginForm()) {%>
    
    <% = Html.AntiForgeryToken() %>
       
        <p>
            <label for="Title"><%= Resources.Strings.TitleFormLabel %></label>
            <%= Html.TextBox("story.Title", "", new { style = "width:100%;" })%>
            <%= Html.ValidationMessage("story.Title", "*")%>
        </p>
        <p>            
            <%= Html.TextArea("story.TextBody", new { style = "width:100%; height:330px;" })%>
            <%= Html.ValidationMessage("story.TextBody", "*")%>
            <div class="wmd-preview"></div>
<script type="text/javascript">
  // to set WMD's options programatically, define a "wmd_options" object with whatever settings
  // you want to override.  Here are the defaults:
  wmd_options = {
    // format sent to the server.  Use "Markdown" to return the markdown source.
    output: "Markdown",

    // line wrapping length for lists, blockquotes, etc.
    //lineLength: 40,

    // toolbar buttons.  Undo and redo get appended automatically.
    buttons: "bold italic | link blockquote code image | ol ul heading hr",

    // option to automatically add WMD to the first textarea found.  See apiExample.html for usage.
    autostart: true
  };
</script>
<script src="../../Scripts/wmd/wmd.js" type="text/javascript"></script>                                                         
            
        </p>
        <p>
            <label><%= Resources.Strings.CategoriesFormLabel%></label>    
            <%
              bool firstSelect = true; 
              foreach (ICategory c in AllCategories)
              {            
                  %>
                  
                  &nbsp;<%=c.Name %>&nbsp;<%=Html.RadioButton("story.Category", c.Id.ToString(), firstSelect)%>
                  
                  <%
                  firstSelect = false;                              
              }                       
            %>                                                                        
        </p>        
        <p>
            <label><%= Resources.Strings.TagsFormLabel%></label>    
            <%=Html.TextBox("story.Tags", null, new { style = "width:100%;" })%>                                           
        </p>        
        <p>
            <input type="submit" value="<%= Resources.Strings.BottomFormSubmit%>" />
        </p>
    <% } %>
    
<%}else
{%>
  <h2>Editar Pregunta</h2>

    <%= Html.ValidationSummary("Un error ha ocurrido y no fue posible agregar la pregunta. Chequea los campos.")%>

    <% using (Html.BeginForm()) {%>    
    
    <% = Html.AntiForgeryToken() %>       
        <%= Html.Hidden("story.Id", ((YoProgramo.Domain.Core.Entities.Story)Model).Id)%>
        <p>
          <label for="story.Title"><%= Resources.Strings.TitleFormLabel %></label>   
            <%= Html.TextBox("story.Title", Server.HtmlDecode(((YoProgramo.Domain.Core.Entities.Story)Model).Title), new { style = "width:100%" })%>
            <%= Html.ValidationMessage("story.Title", "*")%>
        </p>
        <p>                                      
            <%= 
              Html.TextArea("story.TextBody", ((YoProgramo.Domain.Core.Entities.Story)Model).TextBody, new { style = "width:100%; height:330px;" })
              %>
            <%= Html.ValidationMessage("story.Description", "*")%>
            <div class="wmd-preview"></div>
<script type="text/javascript">
  // to set WMD's options programatically, define a "wmd_options" object with whatever settings
  // you want to override.  Here are the defaults:
  wmd_options = {
    // format sent to the server.  Use "Markdown" to return the markdown source.
    output: "Markdown",

    // line wrapping length for lists, blockquotes, etc.
    //lineLength: 40,

    // toolbar buttons.  Undo and redo get appended automatically.
    buttons: "bold italic | link blockquote code image | ol ul heading hr",

    // option to automatically add WMD to the first textarea found.  See apiExample.html for usage.
    autostart: true
  };
</script>
<script src="../../Scripts/wmd/wmd.js" type="text/javascript"></script>                        
        </p>
        <p>
            <label><%= Resources.Strings.CategoriesFormLabel%></label>    
            <% 
              foreach (ICategory c in AllCategories)
              {
                bool selected = ((YoProgramo.Domain.Core.Entities.Story)Model).Category.Id == c.Id ? true : false;
                  %>
                  
                  &nbsp;<%=c.Name %>&nbsp;<%=Html.RadioButton("story.Category", c.Id.ToString(), selected)%>
                  
                  <%                                
              }                       
            %>                                                                        
        </p>        
        <p>
            <label><%= Resources.Strings.TagsFormLabel%></label>    
            <%
              IList<string> tagsNames = new List<string>();
              foreach (ITag t in ((YoProgramo.Domain.Core.Entities.Story)Model).Tags)
              {
                  tagsNames.Add(t.Name);
              }
              string strTags = string.Join(", ", tagsNames.ToArray());                      
            %>
            <%=Html.TextBox("story.Tags", strTags, new { style = "width:100%;" })%>                                           
        </p> 
                
        <p>
            <%= Html.Hidden("story.UserName", ((YoProgramo.Domain.Core.Entities.Story)Model).ByUser.UserName)%>
            User:
            <%= Html.Encode(((YoProgramo.Domain.Core.Entities.Story)Model).ByUser.UserName)%>
        </p>        
        <p>
            <input type="submit" value="<%= Resources.Strings.BottomFormSubmit %>" />
        </p>
    <% } %>

<%
} %>    